﻿using System.Diagnostics;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionLayerParentChanged : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int OldParentLayerIndex { get; set; }
        public int NewParentLayerIndex { get; set; }

        public UserActionLayerParentChanged()
        {
            Action = UserActionTypes.LayerParentChanged;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a LayerParentChanged action");
            if (OldParentLayerIndex == -1)
                LfsRecordController.project.Layers[LayerIndex].ParentLayer = null;
            else
                LfsRecordController.project.Layers[LayerIndex].ParentLayer = LfsRecordController.project.Layers[OldParentLayerIndex];
            LfsRecordController.project.Layers[LayerIndex].UpdatedCurrentValues = CompLayerPropertyUpdateTypes.All;
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a LayerParentChanged action");
            if (NewParentLayerIndex == -1)
                LfsRecordController.project.Layers[LayerIndex].ParentLayer = null;
            else
                LfsRecordController.project.Layers[LayerIndex].ParentLayer = LfsRecordController.project.Layers[NewParentLayerIndex];
            LfsRecordController.project.Layers[LayerIndex].UpdatedCurrentValues = CompLayerPropertyUpdateTypes.All;
        }
    }
}
